//
//  WYEnterprisePageController.m
//  Boss
//
//  Created by admin on 2018/7/4.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYEnterprisePageController.h"
#import "WYEnterpriseNormalCell.h"
#import "WYEnterPrisePageNormalCell.h"
#import "WYTextCell.h"
#import "WYNormalTextCell.h"
#import "WYUserCenterModel.h"
#import "WYHonorCell.h"
#import "WYEnterPriserIntroductionController.h"
#import "WYIndustryController.h"
#import "WYDataPicker.h"
#import "CZHAddressPickerView.h"
#import "UIImage+WYSaveImage.h"
#import "WYUploadModel.h"
@interface WYEnterprisePageController ()<UITableViewDelegate,UITableViewDataSource,UINavigationControllerDelegate,UIImagePickerControllerDelegate,WYHonorCellDelegate>
@property (nonatomic,strong)NSArray *sectionArray;
@property (nonatomic,strong)WYUserCenterModel *model;
@property (nonatomic,strong)NSArray *nameArray;
@property (nonatomic,strong)NSArray *honnorArray;
@property (nonatomic,strong)  WYDataPicker *datePicker;
@property (nonatomic,strong)NSString *date;
@property (nonatomic, copy) NSString *province;

@property (nonatomic, copy) NSString *city;

@property (nonatomic, copy) NSString *area;

@property (nonatomic,strong)NSString *pathString;

@property (nonatomic,strong)WYUploadModel *upmodel;

@end

@implementation WYEnterprisePageController
-(NSArray *)nameArray
{
    if (!_nameArray) {
        _nameArray = @[@"添加企业简介",@"选择所属行业",@"请选择所在地区",@"选择创立时间",@"添加企业荣誉"];
    }
    return _nameArray;
}
-(NSArray *)sectionArray
{
    if (!_sectionArray) {
        _sectionArray = @[@"企业简介",@"所属行业",@"所在地区",@"创立时间",@"企业荣誉墙"];
    }
    return _sectionArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    //self.view.backgroundColor = [UIColor redColor];
    [self setupUI];
   // [self loadData];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(refreshMessageDate) name:@"refreshMessageDate" object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(didChangeHeightWithHonor:) name:@"didChangeHeight" object:nil];
    self.view.backgroundColor = [UIColor whiteColor];
    
//    self.automaticallyAdjustsScrollViewInsets = NO;
//
//    if (@available(iOS 11, *)) {
//        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
//
//    }
    
}
-(void)refreshMessageDate
{
   // [self loadData];
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSLog(@"-------------------------------------------------------------------------");
    
    
}


//-(void)loadData
//{
//    WEAKSELF
//    [WYHttpServer getIntoPersonHomePageSucessBlock:^(BOOL success, id response, NSString *errorMessage) {
//        if (success) {
//            self.honnorArray = nil;
//            weakSelf.model = [WYUserCenterModel getUserCenterModelFromJson:response[@"result"]];
//            if (weakSelf.model.companyHonor.length) {
//                NSArray *array =[weakSelf.model.companyHonor componentsSeparatedByString:@","];
//                if (array.count) {
//                    weakSelf.honnorArray = array;
//                }
//
//            }
//
//            [weakSelf.tableView reloadData];
//        }
//
//
//
//
//    }];
//}
//
//
//
//-(void)setupUI
//{
//    [self.view addSubview:self.tableView];
//
////    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
////        make.left.right.bottom.top.mas_equalTo(0);
////    }];
//
//
//
////    [self.tableView registerClass:[UITableViewCell class] forHeaderFooterViewReuseIdentifier:@"cell"];
//    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
//    [self.tableView registerNib:[UINib nibWithNibName:@"WYEnterpriseNormalCell" bundle:nil] forCellReuseIdentifier:@"WYEnterpriseNormalCell"];
//    [self.tableView registerNib:[UINib nibWithNibName:@"WYEnterPrisePageNormalCell" bundle:nil] forCellReuseIdentifier:@"WYEnterPrisePageNormalCell"];
//    [self.tableView registerClass:[WYTextCell class] forCellReuseIdentifier:@"WYTextCell"];
//    [self.tableView registerNib:[UINib nibWithNibName:@"WYNormalTextCell" bundle:nil] forCellReuseIdentifier:@"WYNormalTextCell"];
//    [self.tableView registerNib:[UINib nibWithNibName:@"WYHonorCell" bundle:nil] forCellReuseIdentifier:@"WYHonorCell"];
//
//
//    self.tableView.estimatedRowHeight = 66;
//    self.tableView.estimatedSectionFooterHeight = 0;
//    self.tableView.estimatedSectionHeaderHeight = 50;
//    WYDataPicker *datePicker = [[WYDataPicker alloc]initWithFrame:CGRectMake(0, kScreenHeight-214, kScreenWidth, 214)];
//    WEAKSELF
//    datePicker.complete = ^(NSString *date) {
//        //        weakSelf.ageLabel.text =[NSString stringWithFormat:@"%.0f",[weakSelf calculateAge:date]];
//        weakSelf.date = date;
//        [weakSelf editTime];
//        [weakSelf.datePicker removeFromSuperview];
//        [weakSelf.maskView removeFromSuperview];
//
//    };
//    datePicker.cancel = ^(NSString *date) {
//        [weakSelf.datePicker removeFromSuperview];
//        [weakSelf.maskView removeFromSuperview];
//    };
//
//
//   // [self.view addSubview:datePicker];
////    [datePicker mas_makeConstraints:^(MASConstraintMaker *make) {
////        make.bottom.left.right.mas_equalTo(0);
////        make.height.mas_equalTo(214);
////    }];
//
//
//
//   // datePicker.hidden = YES;
//    self.datePicker = datePicker;
//
//}
//-(void)editTime
//{
//    WEAKSELF
//    [WYHttpServer editComPanyTimeWithTime:self.date SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
//        if (success) {
//            [weakSelf loadData];
//        }
//    }];
//
//
//}
//#pragma mark - UIScrollViewDelegate
//
//- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
//
//    if (!self.vcCanScroll) {
//        scrollView.contentOffset = CGPointZero;
//    }
//    if (scrollView.contentOffset.y <= 0) {
//        self.vcCanScroll = NO;
//        scrollView.contentOffset = CGPointZero;
//        //到顶通知父视图改变状态
//        [[NSNotificationCenter defaultCenter] postNotificationName:@"leaveTop" object:nil];
//    }
//}
//
//#pragma mark - Table view data source
//
//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//    return 5;
//}
//
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//    return 1;
//}
//
//
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//    if (indexPath.section==0) {
//        if (self.model.companyIntro.length) {
//            WYNormalTextCell *cell =[tableView dequeueReusableCellWithIdentifier:@"WYNormalTextCell" forIndexPath:indexPath];
//            if (!cell) {
//                cell = [[NSBundle mainBundle]loadNibNamed:@"WYNormalTextCell" owner:nil options:nil].firstObject;
//            }
//             cell.selectionStyle = UITableViewCellSelectionStyleNone;
//            cell.label.text =self.model.companyIntro;
//            return cell;
//        }else{
//            WYEnterpriseNormalCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYEnterpriseNormalCell" forIndexPath:indexPath];
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//            return cell;
//        }
//    }
//    if (indexPath.section==1) {
//        if (self.model.profession.length) {
//            WYNormalTextCell *cell =[tableView dequeueReusableCellWithIdentifier:@"WYNormalTextCell" forIndexPath:indexPath];
//            if (!cell) {
//                cell = [[NSBundle mainBundle]loadNibNamed:@"WYNormalTextCell" owner:nil options:nil].firstObject;
//            }
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//            cell.label.text =self.model.profession;
//            return cell;
//        }else{
//            WYEnterPrisePageNormalCell *cell =[tableView dequeueReusableCellWithIdentifier:@"WYEnterPrisePageNormalCell" forIndexPath:indexPath];
//            if (!cell) {
//                cell = [[NSBundle mainBundle]loadNibNamed:@"WYEnterPrisePageNormalCell" owner:nil options:nil].firstObject;
//            }
//            cell.nameLabel.text = self.nameArray[indexPath.section];
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//            return cell;
//
//        }
//    }
//    if (indexPath.section==2) {
//        if (self.model.companyAddress.length) {
//            WYNormalTextCell *cell =[tableView dequeueReusableCellWithIdentifier:@"WYNormalTextCell" forIndexPath:indexPath];
//            if (!cell) {
//                cell = [[NSBundle mainBundle]loadNibNamed:@"WYNormalTextCell" owner:nil options:nil].firstObject;
//            }
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//            cell.label.text =self.model.companyAddress;
//            return cell;
//        }else{
//            WYEnterPrisePageNormalCell *cell =[tableView dequeueReusableCellWithIdentifier:@"WYEnterPrisePageNormalCell" forIndexPath:indexPath];
//            if (!cell) {
//                cell = [[NSBundle mainBundle]loadNibNamed:@"WYEnterPrisePageNormalCell" owner:nil options:nil].firstObject;
//            }
//            cell.nameLabel.text = self.nameArray[indexPath.section];
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//            return cell;
//
//        }
//    }
//    if (indexPath.section==3) {
//        if (self.model.registerTime.length) {
//            WYNormalTextCell *cell =[tableView dequeueReusableCellWithIdentifier:@"WYNormalTextCell" forIndexPath:indexPath];
//            if (!cell) {
//                cell = [[NSBundle mainBundle]loadNibNamed:@"WYNormalTextCell" owner:nil options:nil].firstObject;
//            }
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//            cell.label.text =self.model.registerTime;
//            return cell;
//        }else{
//            WYEnterPrisePageNormalCell *cell =[tableView dequeueReusableCellWithIdentifier:@"WYEnterPrisePageNormalCell" forIndexPath:indexPath];
//            if (!cell) {
//                cell = [[NSBundle mainBundle]loadNibNamed:@"WYEnterPrisePageNormalCell" owner:nil options:nil].firstObject;
//            }
//            cell.nameLabel.text = self.nameArray[indexPath.section];
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//            return cell;
//
//        }
//    }
//    if (indexPath.section==4) {
//        if (self.honnorArray.count) {
//            WYHonorCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYHonorCell" forIndexPath:indexPath];
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//            cell.dataArray = self.honnorArray.mutableCopy;
//            cell.delegate = self;
//            return cell;
//        }else{
//            WYEnterPrisePageNormalCell *cell =[tableView dequeueReusableCellWithIdentifier:@"WYEnterPrisePageNormalCell" forIndexPath:indexPath];
//            if (!cell) {
//                cell = [[NSBundle mainBundle]loadNibNamed:@"WYEnterPrisePageNormalCell" owner:nil options:nil].firstObject;
//            }
//            cell.nameLabel.text = self.nameArray[indexPath.section];
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//            return cell;
//
//        }
//    }
//    return nil;
//}
//-(void)didChangeHeightWithHonor:(WYHonorCell *)cell
//{
//    [self.tableView reloadData];
//}
//
//- (void)didSelectImageViewWithImage:(UIImage *)image WithImageUrl:(NSString *)url WithDataArray:(NSArray *)dataArray WithIndex:(NSIndexPath *)indexPath
//{
//    [[NSNotificationCenter defaultCenter]postNotificationName:@"previewHonnor" object:@{@"image":image,@"url":url,@"dataArray":dataArray,@"indexPath":indexPath}];
//}
//
//-(void)didChangeHeight:(WYHonorCell *)cell
//{
//    [self.tableView reloadData];
//}
//
//-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
//{
//    UIView *view = [[UIView alloc]init];
//    UILabel *label = [[UILabel alloc]init];
//    [view addSubview:label];
//    [label mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(16);
//        make.top.mas_equalTo(20);
//    }];
//    label.text = self.sectionArray[section];
//    label.font = [UIFont fontWithName:@"PingFangSC-Medium" size:16];
//    // NSLog(@"%@",[UIFont familyNames]);
//
//    view.backgroundColor = [UIColor whiteColor];
//
//    return view;
//}
//-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
//{
//    return 50;
//}
//-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
//{
//    return 0.00001;
//}
//-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
//{
//   // self.datePicker.hidden = YES;
//    if (indexPath.section==0) {
//        if (!self.model.companyIntro.length) {
//
//            //            WYEnterPriserIntroductionController *pvc = [[WYEnterPriserIntroductionController alloc]init];
//            //            [self.selfVC.navigationController pushViewController:pvc animated:YES];
//
//            [[NSNotificationCenter defaultCenter]postNotificationName:@"WYEnterPriserIntroductionController" object:nil];
//
//
//        }
//    }
//    if (indexPath.section==1) {
//        if (!self.model.profession.length) {
//            //            WYIndustryController *idc= [[WYIndustryController alloc]init];
//            //            [self.selfVC.navigationController pushViewController:idc animated:YES];
//
//            [[NSNotificationCenter defaultCenter]postNotificationName:@"WYIndustryController" object:nil];
//        }
//
//    }
//    if (indexPath.section==2) {
//        if (!self.model.companyAddress.length) {
//            WEAKSELF
//            [CZHAddressPickerView areaPickerViewWithProvince:self.province city:self.city area:self.area areaBlock:^(NSString *province, NSString *city, NSString *area) {
//                // CZHStrongS elf(self);
//                weakSelf.province = province;
//                weakSelf.city = city;
//                weakSelf.area = area;
//                //weakSelf.addressLabel.text = [NSString stringWithFormat:@"%@%@%@",province,city,area];
//                [weakSelf editAddres];
//            }];
//        }
//
//    }
//    if (indexPath.section==3) {
//        if (!self.model.registerTime.length) {
//            //self.datePicker.hidden = NO;
//            [[UIApplication sharedApplication].keyWindow addSubview:self.maskView];
//            [[UIApplication sharedApplication].keyWindow addSubview:self.datePicker];
//
//
//
//        }
//    }
//    if (indexPath.section==4) {
//        if (!self.honnorArray.count) {
//            WEAKSELF
//            UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
//            imagePickerController.delegate = self; //设置代理
//            imagePickerController.allowsEditing = YES;
//            imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
//            UIAlertController * alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:(UIAlertControllerStyleActionSheet)];
//            UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//            }];
//
//            UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//                imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
//                [weakSelf presentViewController:imagePickerController animated:YES completion:nil];
//            }];
//
//
//            UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//                if (@available(iOS 11, *)) {
//                    UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
//
//                }
//                imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//                [weakSelf presentViewController:imagePickerController animated:YES completion:nil];
//            }];
//            [alertController addAction:action1];
//            [alertController addAction:action2];
//            [alertController addAction:action3];
//            UITableViewCell *cell =[tableView cellForRowAtIndexPath:indexPath];
//            if (IS_IPAD) {
//                UIPopoverPresentationController *popPresenter = [alertController popoverPresentationController];
//                popPresenter.sourceView = cell;
//                popPresenter.sourceRect = cell.bounds;
//                [self presentViewController:alertController animated:YES completion:nil];
//
//            }else{
//                [self presentViewController:alertController animated:YES completion:nil];
//            }
//        }
//    }
//
//}
//-(void)editAddres
//{
//    WEAKSELF
//    [WYHttpServer editComPanyAddressWithadddress:[NSString stringWithFormat:@"%@%@%@",self.province,self.city,self.area] SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
//        if (success) {
//            [weakSelf loadData];
//        }else{
//
//        }
//    }];
//}
//-(UITableView *)tableView
//{
//    if (!_tableView) {
//        CGRect frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight-self.navHeight-self.tabHeight);
//        _tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStyleGrouped];
//        _tableView.delegate = self;
//        _tableView.dataSource = self;
//        _tableView.tableFooterView = [[UIView alloc]init];
//        [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
//        _tableView.backgroundColor = [UIColor whiteColor];
//    }
//    return _tableView;
//}
//
//
//#pragma mark  添加企业荣誉
//-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
//{
//    if (@available(iOS 11, *)) {
//        UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
//    }
//    [picker dismissViewControllerAnimated:YES completion:nil];
//}
//-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
//{
//    if (@available(iOS 11, *)) {
//        UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
//    }
//    [picker dismissViewControllerAnimated:YES completion:^{}];
//    UIImage *photo = [info objectForKey:UIImagePickerControllerOriginalImage];
//    NSData * imageDate = UIImageJPEGRepresentation(photo, 0.1);
//    UIImage *image = [UIImage imageWithData:imageDate];
//
//    NSString *path = [image QCloudTempFilePathWithExtension:@"PNG"];
//    self.pathString = path;
//    [UIImagePNGRepresentation(image) writeToFile:path atomically:YES];
//    //   [MBProgressHUD showHUDAddedTo:self.view animated:YES];
//    // [self showLoading:@""];
//    WEAKSELF
//    [WYHttpServer uploadImageSucessBlock:^(BOOL success, id response, NSString *errorMessage) {
//        WYUploadModel *model = [WYUploadModel getupLoadModelFromJson:response[@"result"]];
//        [weakSelf upLoadWithPath:model.uploadUrl];
//        weakSelf.upmodel = model;
//    }];
//}
//-(void)upLoadWithPath:(NSString *)path
//{
//    WEAKSELF
//    [WYHttpServer PUTWithURLStr:path filePath:self.pathString SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
//        if (success) {
//            //  [MBProgressHUD hideHUDForView:self.view animated:YES];
//            // [self hideLoading];
//            //            [weakSelf editHeaderImageview];
//            [weakSelf addHonor];
//        }else{
//            //[weakSelf toast:errorMessage];
//        }
//
//    }];
//}
//-(void)addHonor
//{
//    WEAKSELF
//    [WYHttpServer addHonor:self.upmodel.visitUrl SucessBlock:^(BOOL success, id response, NSString *errorMessage) {
//        if (success) {
//            [weakSelf toast:@"添加成功"];
//            [weakSelf loadData];
//        }else{
//            [weakSelf toast:errorMessage];
//        }
//    }];
//}
//
//
//-(void)dealloc
//{
//    NSLog(@"这个界面被销毁了吗？？？？？？？/");
//
//
//}

@end
